package homework.test2;

import java.io.*;

/*
	2.使用字节缓冲流
		复制一个视频文件
			1.1 要去1:一次多一个字节
			1.2 要去2:一次读一个字节数组
 */
public class Demo2 {
    public static void main(String[] args) throws IOException {
        FileInputStream fis = new FileInputStream("Day12\\src\\homework\\a.mp4");
        FileOutputStream fos1 = new FileOutputStream("Day12\\src\\homework\\test2\\b.mp4");
        FileOutputStream fos2 = new FileOutputStream("Day12\\src\\homework\\test2\\c.mp4");

        BufferedInputStream bis = new BufferedInputStream(fis);
        BufferedOutputStream bos1 = new BufferedOutputStream(fos1);
        BufferedOutputStream bos2 = new BufferedOutputStream(fos2);


        //1.读字节
        long start1 = System.currentTimeMillis();
        int b;
        while ((b = bis.read()) != -1){
            bos1.write(b);
        }
        bos1.close();
        long end1 = System.currentTimeMillis();
        System.out.println(end1-start1);

        //2.读数组
         //记录开始时间
        long start2 = System.currentTimeMillis();
        byte [] bytes = new byte[1024];
        int len;
        while ((len = bis.read(bytes)) != -1){
            bos2.write(bytes,0,len);
        }
        bis.close();
        bos2.close();
        long end2 = System.currentTimeMillis();
        System.out.println(end2-start2);
    }
}
